﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;
using System.Web;

namespace MethodWorx.CMS.Workflow.RefreshCurrentPage
{
    public class RefreshCurrentPageWorkflowComponent : WorkflowComponent<RefreshCurrentPageController>
    {
        public RefreshCurrentPageWorkflowComponent(Plugin plugin) : base(plugin)
        {

        }

        public static Guid ComponentId = new Guid("{81F53913-C9FD-4E53-B2CD-F8CE6DD30A22}");

        public override Guid Id
        {
            get { return ComponentId;  }
        }

        public override string Category
        {
            get { return "Web";  }
        }

        public override string Name
        {
            get { return "Refresh Current Page";  }
        }

        public override string Description
        {
            get { return "Refreshes the current page and allows optional parameters"; }
        }

        public override StepExecutionResult Execute(IWorkflowExecutionContext context, IWorkflowConfiguration configuration)
        {
            return StepExecutionResult.Finish(() =>
                                                  {
                                                      var current = HttpContext.Current;
                                                      if (current != null)
                                                      {
                                                          current.Response.Redirect(current.Request.Url.PathAndQuery);
                                                      }
                                                  });
        }
    }
}
